<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>添加用户</title>
    <link rel="stylesheet" th:href="@{/X-admin/css/font.css}">
    <link rel="stylesheet" th:href="@{/X-admin/css/xadmin.css}">
    <script type="text/javascript" th:src="@{/js/jquery.min.js}"></script>
    <script th:src="@{/X-admin/lib/layui/layui.js}" charset="utf-8"></script>
    <script type="text/javascript" th:src="@{/X-admin/js/xadmin.js}"></script>
</head>
<body>
<form class="layui-form">
    <div class="layui-form-item">
        <label for="username" class="layui-form-label">
            <span class="x-red">*</span>用户名
        </label>
        <div class="layui-input-inline">
            <input type="hidden" id="id" name="id" th:value="${user.id}"/>
            <input type="text" th:value="${user.username}" id="username" name="username" required="" lay-verify="required"
                   autocomplete="off" class="layui-input">
        </div>
        <div class="layui-form-mid layui-word-aux">
            <span class="x-red">*</span>将会成为您唯一的登入名
        </div>
    </div>
    <div class="layui-form-item">
        <label for="phone" class="layui-form-label">
            <span class="x-red">*</span>手机
        </label>
        <div class="layui-input-inline">
            <input type="text" th:value="${user.phone}" id="phone" name="phone" required="" lay-verify="phone"
                   autocomplete="off" class="layui-input">
        </div>
        <div class="layui-form-mid layui-word-aux">
            <span class="x-red">*</span>将会成为您唯一的登入名
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">性别</label>
        <div class="layui-input-block">
            <input type="radio" name="sex" value="1" title="男" th:checked="${user.sex==1}" />
            <input type="radio" name="sex" value="0" title="女" th:checked="${user.sex==0}" />
        </div>
    </div>

    <div class="layui-form-item">
        <label  class="layui-form-label">
        </label>
        <button  class="layui-btn" lay-filter="add" lay-submit="">
            保存
        </button>
    </div>
</form>

<script>layui.use(['form', 'layer', 'laydate'],
    function() {
        $ = layui.jquery;
        var form = layui.form,
            layer = layui.layer,
            laydate = layui.laydate;

        //监听提交
        form.on('submit(add)',
            function(data) {

                $.ajax({
                    url: '/user/edit',
                    type: 'post',
                    data: data.field,
                    dataType: 'json',
                    success: function (result) {
                        if(result.code == 0){
                            /*layer.alert("修改成功", {
                                    icon: 6
                                },
                                function() {
                                    //关闭当前frame
                                    xadmin.close();
                                    // 可以对父窗口进行刷新
                                    xadmin.father_reload();
                                });*/
                            xadmin.close();
                            // 可以对父窗口进行刷新
                            xadmin.father_reload();
                        }else{
                            layer.alert(result.msg);
                        }
                    }
                })

                return false;
            });

    });
function getAllRole(callback) {
    $.ajax({
        url: '/role/all',
        type: 'get',
        dataType: 'json',
        success: function (result) {
            var html = '';
            if(result.datas && result.datas.length > 0) {
                for(i in result.datas) {
                    var data = result.datas[i];
                    html += '<input type="radio" name="roleId" value="'+data.id+'" title="'+data.name+'" >' +
                        '<div class="layui-unselect layui-form-radio layui-form-radioed"><i class="layui-main layui-icon"></i><div>'+data.name+'</div></div>'
                }
                $('.show-role-container').html(html);
                callback();
            }
        }
    });
}
</script>

</body>

</html>